<template>
  <div class="main">
    <h1>Welcome to my world!</h1>
    <input
        type="text"
        name="username"
        id="username"
        placeholder="User Name"
        v-model:value="username"
    />
    <br />
    <input
        type="password"
        name="password"
        id="password"
        placeholder="P@$$W0RD"
        v-model:value="password"
    />
    <br />
    <input
        type="button"
        value="Done!"
        class="button"
        id="done"
        @click="login"
    />
    <br />
  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      username: "",
      password: ""
    }
  },
  methods: {
    login() {
      axios.post("/api/login", {
        username: this.username,
        password: this.password
      }).then(resp => {
        if (resp.data.data === "登录成功") {
          this.$router.push("/list")
        }else{
          this.$message({
            message: "账号密码错误",
            type: "error"
          })
        }
      }).catch()
    },
    loginCheck() {
      axios.get("/api/login/check").then(resp => {
        if (resp.data.code === 200) {
          this.$router.push("/list")
        }
      })
    }
  },
  mounted() {
    this.loginCheck()
  }
};
</script>

<style scoped>
/* Import Poppins font: */
@import url("https://fonts.googleapis.com/css2?family=Poppins&display=swap");

.main {
  background: rgba(255, 255, 255, 0.4);
  position: absolute;
  top: 20%;
  left: 30%;
  width: 40%;
  text-align: center;
  padding: 5px;
  border-radius: 3rem;
  box-shadow: 0px 0px 8px -5px #000000;
  padding-top: 3%;
  padding-bottom: 5%;
  font-family: "Poppins", sans-serif;
}

h1 {
  cursor: default;
  user-select: none;
}

input {
  border-radius: 3rem;
  border: none;
  padding: 10px;
  text-align: center;
  outline: none;
  margin: 10px;
  width: 30%;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
  font-weight: 400;
}

input:hover {
  box-shadow: 0px 0px 8px -5px #000000;
}

input:active {
  box-shadow: 0px 0px 8px -5px #000000;
}

#done {
  background: lightgreen;
}

.button {
  cursor: pointer;
  user-select: none;
}

img {
  height: 2.2rem;
  margin: 10px;
  user-select: none;
}

img:hover {
  box-shadow: 0px 0px 8px -5px #000000;
  cursor: pointer;
  border-radius: 200rem;
}
</style>